﻿using System;
using System.Collections.Generic;
using KZ.Exception;
using KZ.Lottery.DAL;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;

namespace KZ.Lottery.BLL
{
    public class RuleBLL
    {
        RuleDAL _RuleDAL = new RuleDAL();

        public static Rule GetRule(string ruleID)
        {
            return RuleDAL.GetRule(ruleID);
        }

        public static List<Rule> GetRuleList()
        {
            return RuleDAL.GetRuleList();
        }

        public static bool DeleteRule(string ruleID)
        {
            return RuleDAL.DeleteRule(ruleID);
        }

        public static bool ActivateRule(string ruleID)
        {
            return RuleDAL.UpdateRuleIsActived(ruleID, true);
        }

        public static bool InactivateRule(string ruleID)
        {
            return RuleDAL.UpdateRuleIsActived(ruleID, false);
        }

        public bool InsertRule(Rule rule)
        {
            ValidateData(rule);
            return _RuleDAL.InsertRuleAndDetail(rule);
        }

        public bool UpdateRule(Rule rule)
        {
            ValidateData(rule);
            return _RuleDAL.UpdateRuleAndDetail(rule);
        }

        private void ValidateData(Rule rule)
        {
            if (String.IsNullOrEmpty(rule.RuleName)) { throw new BusinessLogicException(KZ_Message.BLM_ERR_RULENAME_REQUIRE); }
            if (rule.RuleDetailList.Count == 0) { throw new BusinessLogicException(KZ_Message.BLM_ERR_RULEDETAIL_REQUIRE); }
        }
    }
}